package dict.agency;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import utils.MailUtil;

public class EtpDict {

	public static Map<String, String> STATE = new HashMap<String, String>();
	public static Map<String, String> RISK = new HashMap<String, String>();
	public static Map<String, Long> ALERT = new HashMap<String, Long>();
	public static Map<String, Long> HIDE = new HashMap<String, Long>();

	static {
		
		STATE.put("success", "Congratulations ,transaction successful");
		STATE.put("failure", "Transaction failed");
		
		RISK.put("929", "929");
		
		ALERT.put("555", 0L);
		ALERT.put("254", 0L);
		ALERT.put("258", 0L);
		
		//HIDE.put("9905", 0);
	}

	public static synchronized String message(String code) {
		if (STATE.containsKey(code)) {
			return STATE.get(code).toString();
		}
		return "unknown exception";
	}
	
	public static synchronized void warning(String code,int limit){
		String name="ETP";
		String time= new SimpleDateFormat("HH:mm:ss").format(new Date());
		if(ALERT.containsKey(code)){
			ALERT.put(code, ALERT.get(code)+1);
			if(new Integer(ALERT.get(code).toString())>limit){
				ALERT.put(code, 0L);
				MailUtil.sendEmail(MailUtil.tos, "警告", "[" + time+ "]"+name+"返回码["+code+"]超过["+limit+"]次");
			}
		}
	}

}
